package com.fr.report;

import com.fr.base.core.ComparatorUtils;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLReadable;
import com.fr.base.xml.XMLableReader;
import com.fr.data.TableData;
import com.fr.data.core.DataXMLUtils;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public abstract class AbstractTableDataSource
  implements TableDataSource
{
  private static final String XML_TAG = "TableDataMap";
  protected List tableDataNameList = new ArrayList();
  protected List tableDataList = new ArrayList();

  public Iterator getTableDataNameIterator()
  {
    return this.tableDataNameList.iterator();
  }

  public TableData getTableData(String paramString)
  {
    int i = this.tableDataNameList.indexOf(paramString);
    if (i == -1)
      return null;
    return ((TableData)this.tableDataList.get(i));
  }

  public void putTableData(String paramString, TableData paramTableData)
  {
    if (paramString == null)
      return;
    int i = this.tableDataNameList.indexOf(paramString);
    if (paramTableData == null)
    {
      if (i != -1)
      {
        this.tableDataNameList.remove(i);
        this.tableDataList.remove(i);
      }
    }
    else if (i != -1)
    {
      this.tableDataList.set(i, paramTableData);
    }
    else
    {
      this.tableDataNameList.add(paramString);
      this.tableDataList.add(paramTableData);
    }
  }

  public boolean renameTableData(String paramString1, String paramString2)
  {
    if ((paramString2 == null) || (paramString1 == null))
      return false;
    if (ComparatorUtils.equals(paramString1, paramString2))
      return false;
    int i = this.tableDataNameList.indexOf(paramString1);
    if (i != -1)
      this.tableDataNameList.set(i, paramString2);
    else
      return false;
    return true;
  }

  public void removeTableData(String paramString)
  {
    if (paramString == null)
      return;
    int i = this.tableDataNameList.indexOf(paramString);
    if (i != -1)
    {
      this.tableDataNameList.remove(i);
      this.tableDataList.remove(i);
    }
  }

  public void clearAllTableData()
  {
    this.tableDataNameList.clear();
    this.tableDataList.clear();
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    if (paramXMLableReader.isChildNode())
    {
      String str = paramXMLableReader.getTagName();
      if (str.equals("TableDataMap"))
        paramXMLableReader.readXMLObject(new XMLReadable(this)
        {
          private final AbstractTableDataSource this$0;

          public void readXML()
          {
            if (paramXMLableReader.isAttr())
              this.this$0.clearAllTableData();
            if (paramXMLableReader.isChildNode())
            {
              String str = paramXMLableReader.getAttr("name");
              if ("NameTableData".equals(paramXMLableReader.getTagName()))
              {
                paramXMLableReader.readXMLObject(new AbstractTableDataSource.2(this, str));
              }
              else
              {
                TableData localTableData = DataXMLUtils.readXMLTableData(paramXMLableReader);
                this.this$0.putTableData(str, localTableData);
              }
            }
          }

          static AbstractTableDataSource access$000(1 param1)
          {
            return param1.this$0;
          }
        });
    }
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    if ((this.tableDataNameList != null) && (this.tableDataNameList.size() > 0))
    {
      paramXMLPrintWriter.startTAG("TableDataMap");
      for (int i = 0; i < this.tableDataNameList.size(); ++i)
      {
        String str = (String)this.tableDataNameList.get(i);
        TableData localTableData = (TableData)this.tableDataList.get(i);
        DataXMLUtils.writeXMLTableData(paramXMLPrintWriter, localTableData, str);
      }
      paramXMLPrintWriter.end();
    }
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    return super.clone();
  }
}